package hanyuchao.dao;

import hanyuchao.pojo.HanYuChaoPojo;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.transform.Transformers;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Component()
public class HanYuChaoDao extends HibernateDaoSupport {
    public List<HanYuChaoPojo> querypage(String name) {
        String sql = "select * from j06hanyuchao where name like ? ";
        Query query=getSessionFactory().openSession().createSQLQuery(sql);
        query.setParameter(0,  "%" + name + "%");
        query.setResultTransformer(Transformers.aliasToBean(HanYuChaoPojo.class));
        List<HanYuChaoPojo> list=  query.list();

        return  list;
    }
@Transactional
    public void save(HanYuChaoPojo hanYuChaoPojo) {
    getSessionFactory().openSession().saveOrUpdate(hanYuChaoPojo);
    }
}
